//用户浏览记录
exports.user_browse_record = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([
            //1.浏览课程
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.userBrowseCourse + "/ubr_uid/" + restfulParams.u_id,
                        method: 'POST',
                        data: {
                            fields: ["oc_id", "oc_title", "oc_title_image", "oc_course_count", "oc_sales_volume", "oc_new_price", "o_name"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.browseCourseData = data.data;
                        cb();
                    }
                );

            },
            //2.浏览活动
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.userBrowseActivity + "/ubr_uid/" + restfulParams.u_id,
                        method: 'POST',
                        data: {
                            fields: ["oa_id", "oa_title", "oa_title_image", "oa_join_count", "oa_type", "l_name"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.browseActivityData = data.data;
                        cb();
                    }
                );

            },
            //查询不同类型的活动
            function (cb) {

                //创建添加任务
                var tasks = [];

                //循环节点列表
                resultData.browseActivityData.forEach(function (item, i) {

                    //创建每一个插入任务
                    tasks.push(function (cb) {
                        //拼团
                        if (item.oa_type == 0) {

                            R.SEND_HTTP(
                                req,
                                {
                                    url: CORE_APIConfig.coreAPI.search_bulk_purchase_activity_config + "/bpac_oaid/" + item.oa_id,
                                    method: 'POST',
                                    data: {
                                        fields: ["bpac_participation_price"].join(",")
                                    }
                                },
                                function (err, data) {

                                    //console.log(data);

                                    item.price = data.data[0].bpac_participation_price;

                                    cb();
                                }
                            );
                            //投票
                        } else if (item.oa_type == 1) {
                            item.price = 0;
                            cb();

                            //砍价
                        } else if (item.oa_type == 2) {
                            item.price = 0;
                            cb();

                            //海报
                        } else if (item.oa_type == 3) {
                            item.price = 0;
                            cb();

                            //助力
                        }else if(item.oa_type == 4){
                            R.SEND_HTTP(
                                req,
                                {
                                    url: CORE_APIConfig.coreAPI.searchDiscountsActivityConfig + "/dac_oaid/" + item.oa_id,
                                    method: 'POST',
                                    data: {
                                        fields: ["dac_new_price"].join(",")
                                    }
                                },
                                function (err, data) {

                                    //console.log(data);

                                    item.price = data.data[0].dac_new_price;

                                    cb();
                                }
                            );
                        }

                    });

                });
                async.waterfall(tasks, cb);
            },

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}